#------------------------------------------------------------
# generatge topics
# hand_coded
#------------------------------------------------------------
util_generate_topics <- function(right_topics) {

  `%>%` <- magrittr::`%>%`

  ##-----------------------------##
  ## EU Integration Dimension

  topics <- tibble::tibble(
    original = unique(right_topics),
    label = NA_character_,
    category = NA_character_
  )

  # EU Treaties and revision of Treaties + # Enlargement
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Treaties in general")
        ) ~ "EU Treaties, Revision of Treaties, and Enlargement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Revision of the Treaties")
        ) ~ "EU Treaties, Revision of Treaties, and Enlargement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("State and evolution of the Union")
        ) ~ "EU Treaties, Revision of Treaties, and Enlargement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Pre-accession and partnership")
        ) ~ "EU Treaties, Revision of Treaties, and Enlargement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Enlargement", ignore_case = TRUE)
        ) ~ "EU Treaties, Revision of Treaties, and Enlargement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Candidate countries", ignore_case = TRUE)
        ) ~ "EU Treaties, Revision of Treaties, and Enlargement",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "EU Treaties, Revision of Treaties, and Enlargement" ~
          "EU Integration",
        TRUE ~ category
      )
    )

  # EU law and implementation
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("EU law")
        ) ~ "EU law, Implementation of EU law, Coordination and Simplication",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("implementation")
        ) ~ "EU law, Implementation of EU law, Coordination and Simplication",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("codification")
        ) ~ "EU law, Implementation of EU law, Coordination and Simplication",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "European statistical legislation"
          )
        ) ~ "EU law, Implementation of EU law, Coordination and Simplication",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label ==
          "EU law, Implementation of EU law, Coordination and Simplication"
        ~ "EU Integration",
        TRUE ~ category
      )
    )

  # Terrorism, crime, police cooperation
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "[Tt]errorism"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = "Control of personal weapons and ammunitions"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = "combat crime"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = "[Pp]olice"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = "Europol"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = "criminal matters"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = "[Jj]udicial cooperation"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = "Action to combat drugs and drug-trafficking"
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Ethical information policy")
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Public security")
        ) ~ "Terrorism, Crime, Police, and Judicial Cooperation",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Terrorism, Crime, Police, and Judicial Cooperation"
        ~ "EU Integration",
        TRUE ~ category
      )
    )

  # EU Institutions, rules of procedure
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Institutions of the Union"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "European Parliament"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "President, members, mandates, political groups"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "EuroCommittees, interparliamentary delegations"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Council of the Union"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "European Council"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Interinstitutional relations"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Agencies and bodies of the EU"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Business of Parliament"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "European Ombudsman"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Cooperation between administrations"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "European Commission"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Relations with interest representatives"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Court of Justice, Court of First Instance"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Relations with Member State governments and national parliaments"
          )
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        stringr::str_detect(
          string = original,
          pattern = "Committees, interparliamentary delegations"
        ) ~ "EU Institutions, Rules of Procedure, Interinstitutional Matters",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label ==
          "EU Institutions, Rules of Procedure, Interinstitutional Matters"
        ~ "EU Integration",
        TRUE ~ category
      )
    )

  # Elections
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Elections"
        ) ~ "EP Elections, Electoral Law, Election Interference",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "EP Elections, Electoral Law, Election Interference"
        ~ "EU Integration",
        TRUE ~ category
      )
    )

  # Common security
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Common security and defence policy (CSDP)")
        ) ~ "Common Security/Cybersecurity",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Common foreign and security policy (CFSP)")
        ) ~ "Common Security/Cybersecurity",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Defence and arms industry"
          )
        ) ~ "Common Security/Cybersecurity",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Armaments control, non-proliferation nuclear weapons"
          )
        ) ~ "Common Security/Cybersecurity",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Cybersecurity, cyberspace policy")
        ) ~ "Common Security/Cybersecurity",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "International information networks and society, internet"
          )
        ) ~ "Common Security/Cybersecurity",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Common Security/Cybersecurity"
        ~ "EU Integration",
        TRUE ~ category
      )
    )

  # Citizens' rights and protection
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Diplomatic and consular protection"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "Fundamental rights in the EU, Charter"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "Social and economic rights"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "Citizen's rights"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "European citizenship"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "Political rights, right to vote and to stand in elections"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "Civil protection"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Protection of privacy and data protection")
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "Public access to information and documents, administrative"
        ) ~ "EU Citizenship, Rights & Protection",
        stringr::str_detect(
          string = original,
          pattern = "Right of petition"
        ) ~ "EU Citizenship, Rights & Protection",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "EU Citizenship, Rights & Protection"
        ~ "EU Integration",
        TRUE ~ category
      )
    )

  # Press and Media
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Press, media freedom and pluralism"
        ) ~ "Press Freedom and Pluralism",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Press Freedom and Pluralism"
        ~ "EU Integration",
        TRUE ~ category
      )
    )

  # Research and Innovation
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "European research area and policy"
        ) ~ "Research and Innovation",
        stringr::str_detect(
          string = original,
          pattern = "Research specific areas"
        ) ~ "Research and Innovation",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Framework programme and research programmes"
          )
        ) ~ "Research and Innovation",
        stringr::str_detect(
          string = original,
          pattern =
            "Framework programme and research programme for Coal and Steel"
        ) ~ "Research and Innovation",
        stringr::str_detect(
          string = original,
          pattern = "Scientific and technological cooperation and agreements"
        ) ~ "Research and Innovation",
        stringr::str_detect(
          string = original,
          pattern = "Innovation"
        ) ~ "Research and Innovation",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("EC, EU framework programme")
        ) ~ "Research and Innovation",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Research and Innovation"
        ~ "EU Integration",
        TRUE ~ category
      )
    )


  ##-----------------------------##
  ## Culture, Identity Dimension
  ##-----------------------------##

  # Gender equality, women's rights
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "[Gg]ender"
        ) ~ "Gender Equality, Women's Rights",
        stringr::str_detect(
          string = original,
          pattern = "[Ww]omen"
        ) ~ "Gender Equality, Women's Rights",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Gender Equality, Women's Rights"
        ~ "Culture, Identity",
        TRUE ~ category
      )
    )

  # Education, Youth
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Education, vocational training and youth"
        ) ~ "Education, Vocational Training, and Youth",
        stringr::str_detect(
          string = original,
          pattern =
            "European area for education, training and lifelong learning"
        ) ~ "Education, Vocational Training, and Youth",
        stringr::str_detect(
          string = original,
          pattern = "Vocational education and training"
        ) ~ "Education, Vocational Training, and Youth",
        stringr::str_detect(
          string = original,
          pattern = "Youth"
        ) ~ "Education, Vocational Training, and Youth",
        stringr::str_detect(
          string = original,
          pattern = paste0(
            "Cooperation and agreements in the fields of ",
            "education, training and youth"
          )
        ) ~ "Education, Vocational Training, and Youth",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Primary and secondary school")
        ) ~ "Education, Vocational Training, and Youth",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Education, Vocational Training, and Youth"
        ~ "Culture, Identity",
        TRUE ~ category
      )
    )

  # EU Values
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "EU values"
        ) ~ "EU Values, Racism, Xenophobia, Diversity",
        stringr::str_detect(
          string = original,
          pattern = "[Rr]acism"
        ) ~ "EU Values, Racism, Xenophobia, Diversity",
        stringr::str_detect(
          string = original,
          pattern = "Common cultural area, cultural diversity"
        ) ~ "EU Values, Racism, Xenophobia, Diversity",
        stringr::str_detect(
          string = original,
          pattern = "Cultural programmes and actions, assistance"
        ) ~ "EU Values, Racism, Xenophobia, Diversity",
        stringr::str_detect(
          string = original,
          pattern = "Heritage and culture protection, movement of works of art"
        ) ~ "EU Values, Racism, Xenophobia, Diversity",
        stringr::str_detect(
          string = original,
          pattern = "Equal treatment of persons, non-discrimination"
        ) ~ "EU Values, Racism, Xenophobia, Diversity",
        stringr::str_detect(
          string = original,
          pattern = "Cultural and artistic activities, books and reading, arts"
        ) ~ "EU Values, Racism, Xenophobia, Diversity",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "EU Values, Racism, Xenophobia, Diversity"
        ~ "Culture, Identity",
        TRUE ~ category
      )
    )

  # Asylum, refugees, Schengen, external borders
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Refugees"
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        stringr::str_detect(
          string = original,
          pattern = "integration of third-country nationals",
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        stringr::str_detect(
          string = original,
          pattern = "Schengen"
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        stringr::str_detect(
          string = original,
          pattern = "[Aa]sylum"
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        stringr::str_detect(
          string = original,
          pattern = "borders"
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        stringr::str_detect(
          string = original,
          pattern = "Migration"
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        stringr::str_detect(
          string = original,
          pattern = "Area of freedom, security and justice"
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        stringr::str_detect(
          string = original,
          pattern = "migrant smuggling"
        ) ~ "Migration, Asylum, Refugees, Schengen, External Borders",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Migration, Asylum, Refugees, Schengen, External Borders"
        ~ "Culture, Identity",
        TRUE ~ category
      )
    )


  # Climate and environment
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "[Cl]imate"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Environment"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Transfrontier pollution"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Soil pollution"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "industrial pollution"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "European ecolabel"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "light industrial waste"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "oil pollution"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Sustainable development"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "water pollution"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Protection of natural resources"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Solid fuels, coal mining, mining industry"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Atmospheric pollution, motor vehicle pollution"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Natural disasters, Solidarity Fund"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Dangerous substances, toxic and radioactive wastes"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "International and regional environment protection measures"
        ) ~ "Climate and Environment",
        stringr::str_detect(
          string = original,
          pattern = "Environmental taxation"
        ) ~ "Climate and Environment",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Climate and Environment"
        ~ "Climate",
        TRUE ~ category
      )
    )

  ##-----------------------------##
  ## Aid, Development, Democracy Promotion

  # External relations and development aid
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Emergency aid, food, humanitarian aid"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Fundamental freedoms, human rights, democracy in general"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with non-governmental organisations, NGOs"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Human rights situation in the world"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "developing countries"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "industrialised countries"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "international organisations"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "European neighbourhood policy"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with Latin America"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with Asian"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with African"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with ACP countries"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "countries of the Middle East"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with Caucasus countries"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with the Mediterranean"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with Russian Federation"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with the Commonwealth"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with South-East Europe"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with third countries"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Development cooperation"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "European Investment Bank"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = paste0(
            "Relations with the countries of the Great ",
            "Maghreb and Maghreb"
          )
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = paste0(
            "Peace preservation, humanitarian and rescue ",
            "tasks, crisis management"
          )
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = paste0(
            "Third-country political situation, local ",
            "and regional conflicts"
          )
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Foreign direct investment"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Foreign and common diplomatic policy"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with central Asian countries"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with central and eastern Europe"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Relations with Turkey"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Macro-financial assistance to third countries"
        ) ~ "External Relations and Development Aid",
        stringr::str_detect(
          string = original,
          pattern = "Emergency, food, humanitarian aid, aid to refugees"
        ) ~ "External Relations and Development Aid",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "External Relations and Development Aid"
        ~ "Aid, Development, Democracy Promotion",
        TRUE ~ category
      )
    )

  ##-----------------------------##
  ## Economics Dimension

  # Budget related issues
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "[Bb]udget"
        ) ~ "EU Budgets",
        stringr::str_detect(
          string = original,
          pattern = "Protecting financial interests of the EU against fraud"
        ) ~ "EU Budgets",
        stringr::str_detect(
          string = original,
          pattern = "Financial regulations"
        ) ~ "EU Budgets",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "[Dd]ischarge"
        ) ~ "EU Budgets",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "EU Budgets"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Energy Policy
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Oil industry, motor fuels"
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = "Solid fuels, coal mining, mining industry"
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = "Energy efficiency"
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = "Gas, electricity, natural gas, biogas"
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Security of energy supply")
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = "Energy policy"
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = "Alternative and renewable energies"
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Cooperation and agreements for energy")
        ) ~ "Energy Policy",
        stringr::str_detect(
          string = original,
          pattern = "Nuclear energy, industry and safety"
        ) ~ "Energy Policy",
        TRUE ~ label
      ),
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Energy Policy"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Agriculture and Fisheries
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "[Ff]ish"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Set-aside and conversion of land"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "[Aa]gricultur"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Forestry"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Milk and dairy products"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Fodder plants"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Oleaginous plants"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Organic farming"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Fruit, citrus fruits"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Vegetables"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Processed products, agri-foodstuffs"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Sugar"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Livestock products, in general"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Cereals, rice"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Livestock farming"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Feedingstuffs, animal nutrition"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Meat"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "organic farming"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Crop products in general, floriculture"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Plant health legislation"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Agro-genetics"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Agrimonetary policy, compensatory amounts"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Aquaculture"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Animal protection"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Animal health requirements"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Foodstuffs, foodstuffs legislation"
        ) ~ "Agriculture and Fisheries",
        stringr::str_detect(
          string = original,
          pattern = "Wine, alcoholic and non-alcoholic beverages"
        ) ~ "Agriculture and Fisheries",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Agriculture and Fisheries"
        ~ "Economics",
        TRUE ~ category
      )
    )


  # Single market
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Customs union"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "[Ff]ree movement"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Industrial competitiveness"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "State aids and interventions"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "single market"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = paste0(
            "Industrial property, European patent, Community patent, design ",
            "and pattern"
          )
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "New technologies"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern =
            "Recognition of diplomas, equivalence of studies and training"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Entrepreneurship, liberal professions"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Standardisation"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Competition"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Small and medium-sized enterprises (SME), craft industries"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Food industry"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Savings"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Radiocommunications, broadcasting"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Financial management of undertakings, business"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Business environment, reduction of the"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Communications by satellite"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Television, cable, digital, mobile"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Audiovisual industry and services"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Manufactured goods"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Iron and steel industry, metallurgical industry"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern =
            "Electronic and mobile communications, personal communications"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern =
            "Electronics, electrotechnical industries, ICT, robotics"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Services sector"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Professional qualifications, recognition of qualifications"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Information and communication technologies, digital"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Chemical industry, fertilizers, plastics"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Aeronautical industry, aerospace industry"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Company law"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Programmes and actions in audiovisual sector"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Building industry"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern =
            "Social economy, mutual societies, cooperatives, associations"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Intellectual property, copyright"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Textile plants, cotton"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Textile and clothing industry, leathers"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Small and medium-sized enterprises"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Trans-European energy networks"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Trans-European communications networks"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Motor industry, cycle and motorcycle, commercial"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "Shipbuilding, nautical industry"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = "European space policy"
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Relations with EEA/EFTA countries", ignore_case = TRUE
          )
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Public services, of general interest, universal service"
          )
        ) ~ "Single Market, Standardization, Free Movement",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Raw materials")
        ) ~ "Single Market, Standardization, Free Movement",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Single Market, Standardization, Free Movement"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Financial services regulation and Banks
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Banks"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "Electronic money"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "Capital outflow"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "economic fraud"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "Free movement of capital"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "Insurance, pension funds"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "Securities and financial markets"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "Financial services"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        stringr::str_detect(
          string = original,
          pattern = "Financial supervision"
        ) ~ "Financial Services Regulation, Banks, Economic Fraud",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Financial Services Regulation, Banks, Economic Fraud"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # monetary union, price stability
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("European Central Bank (ECB), ESCB")
        ) ~ "Monetary Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Coordination of monetary policies, European Monetary Institute"
          )
        ) ~ "Monetary Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Price policy, price stabilisation")
        ) ~ "Monetary Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Single currency, euro, euro area")
        ) ~ "Monetary Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Economic and monetary system")
        ) ~ "Monetary Policy",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Monetary Policy"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Economic Policy
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("5.05 Economic growth")
        ) ~ "Economic Policy",
        stringr::str_detect(
          string = original,
          pattern = "Economic and monetary system"
        ) ~ "Economic Policy",
        stringr::str_detect(
          string = original,
          pattern = "Public procurement"
        ) ~ "Economic Policy",
        stringr::str_detect(
          string = original,
          pattern = "Flexibility instrument"
        ) ~ "Economic Policy",
        stringr::str_detect(
          string = original,
          pattern = "Enterprise policy, inter-company cooperation"
        ) ~ "Economic Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            paste0(
              "5.10.01 Convergence of economic policies,  public ",
              "deficit, interest rates"
            )
          )
        ) ~ "Economic Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("6.20 Common commercial policy in general")
        ) ~ "Economic Policy",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Economic Policy"
        ~ "Economics",
        TRUE ~ category
      )
    )


  # Transportation and Tourism
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "[Tr]ransport"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = "Air transport and air freight"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = "Road transport agreements and cooperation"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = "Air transport agreements and cooperation"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Rail transport: passengers and freight")
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Road transport: passengers and freight")
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = "Inland waterway transport"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = "Tourism"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = "Trans-European transport networks"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = "Ports policy"
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Maritime transport: passengers and freight")
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Maritime safety")
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Combined transport, multimodal transport")
        ) ~ "Transport and Tourism",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Maritime or inland transport agreements and cooperation"
          )
        ) ~ "Transport and Tourism",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Transport and Tourism"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Cohesion policy
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Cohesion policy, Cohesion Fund (CF)")
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        stringr::str_detect(
          string = original,
          pattern = "Urban policy, cities, town and country planning"
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        stringr::str_detect(
          string = original,
          pattern = "Regional policy"
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        stringr::str_detect(
          string = original,
          pattern = "Regional cooperation, cross-border cooperation"
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        stringr::str_detect(
          string = original,
          pattern =
            "Outlying and outermost regions, overseas countries and territories"
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        stringr::str_detect(
          string = original,
          pattern = "European Regional Development Fund"
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        stringr::str_detect(
          string = original,
          pattern = "Structural funds, investment funds in general, programmes"
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        stringr::str_detect(
          string = original,
          pattern = "Economic, social and territorial cohesion"
        ) ~ "Cohesion Policy, Regional Policy, Structural Funds",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Cohesion Policy, Regional Policy, Structural Funds"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Consumer protection
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Food safety"
        ) ~ "Consumer Protection",
        stringr::str_detect(
          string = original,
          pattern = "Consumers' protection in general"
        ) ~ "Consumer Protection",
        stringr::str_detect(
          string = original,
          pattern = "Consumer information, advertising, labelling"
        ) ~ "Consumer Protection",
        stringr::str_detect(
          string = original,
          pattern = "Consumers' economic and legal interests"
        ) ~ "Consumer Protection",
        stringr::str_detect(
          string = original,
          pattern = "Safety of products and services, product liability"
        ) ~ "Consumer Protection",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            paste0(
              "Business policy, e-commerce, after-sales service, ",
              "commercial distribution"
            )
          )
        ) ~ "Consumer Protection",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Consumer Protection"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Health
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Pharmaceutical products and indust"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Safety of blood and  transfusion"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Health legislation and policy"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Clinical practice and experiments"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Medical research"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Medicine, diseases"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Public health"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Health services, medical institutions"
        ) ~ "Health, Medical Research, Experiments",
        stringr::str_detect(
          string = original,
          pattern = "Drug addiction, alcoholism, smoking"
        ) ~ "Health, Medical Research, Experiments",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Health, Medical Research, Experiments"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Labour Law and Social Policy
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Arrangement of working time, work schedules"
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = "Health and safety at work, occupational medicine"
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            paste0(
              "Workforce, occupational mobility, job conversion, ",
              "working conditions"
            )
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Worker information, participation, trade unions, works councils"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Workers protection and rights, labour law"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Employment: guidelines, actions, Fund"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Social problems: delinquency, violence, crime"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Social and community life, associations, foundations"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Social protection, social security"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Retirement, pensions"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Housing policy"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Social protection, social security"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "The elderly"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Social policy, social charter and protocol"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Family policy, family law, parental leave"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Employment policy, action to combat unemployment"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = paste0(
            "Industrial restructuring, job losses, redundancies, relocations, ",
            "Globalisation Adjustment Fund"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "Social inclusion, poverty, minimum income"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            "People with disabilities"
          )
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("Social dialogue, social partners")
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = "Demography"
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = "Sport"
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(pattern = "European Social Fund (ESF)")
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = "Civil protection"
        ) ~ "Labour Law and Social Policy",
        stringr::str_detect(
          string = original,
          pattern = "Child protection, children's rights"
        ) ~ "Labour Law and Social Policy",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Labour Law and Social Policy"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Trade, Customs, Tariffs
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Export/import control, trade defence, trade barriers"
        ) ~ "Trade, Customs, Tariffs",
        stringr::str_detect(
          string = original,
          pattern = "Generalised scheme of tariff preferences"
        ) ~ "Trade, Customs, Tariffs",
        stringr::str_detect(
          string = original,
          pattern =
            "Trade restrictions, concerted practices, dominant positions"
        ) ~ "Trade, Customs, Tariffs",
        stringr::str_detect(
          string = original,
          pattern = "Bilateral economic and trade agreements and relations"
        ) ~ "Trade, Customs, Tariffs",
        stringr::str_detect(
          string = original,
          pattern = paste0(
            "Union Customs Code, tariffs, preferential arrangements",
            ", rules of origin"
          )
        ) ~ "Trade, Customs, Tariffs",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            paste0(
              "Agreements and relations in the context of the World Trade",
              " Organization (WTO)"
            )
          )
        ) ~ "Trade, Customs, Tariffs",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed("5.03 Global economy and globalisation")
        ) ~ "Trade, Customs, Tariffs",
        stringr::str_detect(
          string = original,
          pattern = stringr::fixed(
            paste0(
              "Multilateral and plurilateral economic and trade",
              " agreements and relations"
            )
          )
        ) ~ "Trade, Customs, Tariffs",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Trade, Customs, Tariffs"
        ~ "Economics",
        TRUE ~ category
      )
    )

  # Tax
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Taxation"
        ) ~ "Taxation",
        stringr::str_detect(
          string = original,
          pattern = "Indirect taxation"
        ) ~ "Taxation",
        stringr::str_detect(
          string = original,
          pattern = "Direct taxation"
        ) ~ "Taxation",
        stringr::str_detect(
          string = original,
          pattern = "Company taxation"
        ) ~ "Taxation",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Taxation"
        ~ "Economics",
        TRUE ~ category
      )
    )


  # Remove categories because they are not unambiguous

  # Ambiguous
  topics <- topics %>%
    dplyr::mutate(
      label = dplyr::case_when(
        stringr::str_detect(
          string = original,
          pattern = "Economic, social and territorial cohesion"
        ) ~ "Ambiguous",
        stringr::str_detect(
          string = original,
          pattern = "Industrial policy"
        ) ~ "Ambiguous",
        TRUE ~ label
      )
    ) %>%
    dplyr::mutate(
      category = dplyr::case_when(
        label == "Ambiguous"
        ~ "Ambiguous",
        TRUE ~ category
      )
    )

  return(topics)
}